//
//  HMWBUserInfo.swift
//  Weibo
//
//  Created by 李学林 on 15/12/7.
//  Copyright © 2015年 tete. All rights reserved.
//
import UIKit

class HMWBUserInfo: NSObject,NSCoding {

    // 用户的id
    var uid: String?
    // 过期时间,单位秒
    var expires_in: NSTimeInterval = 0{
        didSet{
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
//            printLog(expiresDate)
        }
        
    }
    // 用于调用access_token，接口获取授权后的access token
    var access_token: String?
//    // access_token的生命周期（该参数即将废弃，开发者请使用expires_in）。
//    var remind_in: String?
    
    // 到期时间
    var expiresDate : NSDate?
    // 头像大图
    var avatar_large: String?
    // 昵称
    var screen_name: String?
    
    
    
    
    init(dict: [String : AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)

    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
    
    // 解档
    required init(coder aDecoder: NSCoder){
        uid = aDecoder.decodeObjectForKey("uid") as? String
        expiresDate = aDecoder.decodeObjectForKey("expiresDate") as? NSDate
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
    
    }
    

    // 归档
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(uid,forKey: "uid")
        aCoder.encodeObject(expiresDate,forKey: "expiresDate")
        aCoder.encodeObject(access_token,forKey: "access_token")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
    }
    
    

    
    
    override var description: String {
        let keys = ["uid", "expires_in", "access_token","screen_name","avatar_large","expiresDate"]
        return dictionaryWithValuesForKeys(keys).description
    }
    
}
